package com.fr.cell;

import com.fr.base.FRContext;
import com.fr.base.Inter;
import com.fr.base.Style;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.core.FRCoreContext;
import com.fr.cell.clipboard.CellElementsClip;
import com.fr.cell.clipboard.ElementsTransferable;
import com.fr.cell.clipboard.FloatElementsClip;
import com.fr.cell.core.DynamicScrollBar;
import com.fr.cell.core.GUIConstants;
import com.fr.cell.core.GridUtils;
import com.fr.cell.core.RGridLayout;
import com.fr.cell.event.GridSelectionChangeEvent;
import com.fr.cell.event.GridSelectionChangeListener;
import com.fr.cell.event.ReportDataChangeEvent;
import com.fr.cell.event.ReportDataChangeListener;
import com.fr.cell.undo.UndoState;
import com.fr.cell.undo.UndoStateEdit;
import com.fr.report.CellElement;
import com.fr.report.DefaultCellElement;
import com.fr.report.FloatElement;
import com.fr.report.Report;
import com.fr.report.TemplateReport;
import com.fr.report.TemplateWorkBook;
import com.fr.report.cellElement.CellGUIAttr;
import com.fr.report.cellElement.Formula;
import com.fr.report.core.SheetUtils;
import com.fr.util.Utils;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractAction;
import javax.swing.ActionMap;
import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JScrollBar;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.event.EventListenerList;
import javax.swing.undo.UndoManager;

public abstract class ReportPane extends JComponent
{
  private TemplateReport _curReport = null;
  private GridSelection gridSelelction = new GridSelection();
  private static final int Clear_All = 0;
  private static final int Clear_Formats = 1;
  private static final int Clear_Contents = 2;
  private UndoManager undoMananger;
  protected UndoState currentUndoState;
  private boolean supportUndo = true;
  private int undoLimit = 5;
  private boolean undoCacheable = false;
  private boolean supportDefaultParentCalculate = true;
  protected Grid grid;
  protected GridRow gridRow;
  protected GridColumn gridColumn;
  protected GridCorner gridCorner;
  protected JScrollBar verScrollBar;
  protected JScrollBar horScrollBar;
  private EventListenerList reportDataChangeListenerList = new EventListenerList();
  private EventListenerList gridSelectionChangeListenerList = new EventListenerList();
  private transient GridSelectionChangeEvent gridSelectionChangeEvent = null;
  private transient ReportDataChangeEvent reportDataChangeEvent = null;
  private boolean isFormatBrush;
  private boolean columnHeaderVisible = true;
  private boolean rowHeaderVisible = true;
  private boolean verticalScrollBarVisible = true;
  private boolean horizontalScrollBarVisible = true;
  private boolean rowEndless = true;
  private boolean columnEndless = true;

  public ReportPane()
  {
    enableEvents(131072L);
    initComponents();
    setFocusTraversalKeysEnabled(false);
  }

  protected void initComponents()
  {
    setLayout(new RGridLayout());
    if (this.grid == null)
      this.grid = new Grid();
    if (this.gridColumn == null)
      this.gridColumn = new GridColumn();
    if (this.gridRow == null)
      this.gridRow = new GridRow();
    if (this.gridCorner == null)
      this.gridCorner = new GridCorner();
    this.grid.setReportPane(this);
    this.gridColumn.setReportPane(this);
    this.gridRow.setReportPane(this);
    this.gridCorner.setReportPane(this);
    this.verScrollBar = new DynamicScrollBar(1, this);
    this.horScrollBar = new DynamicScrollBar(0, this);
    add("GridCorner", this.gridCorner);
    add("GridColumn", this.gridColumn);
    add("GridRow", this.gridRow);
    add("Grid", this.grid);
    add("VerScrollBar", this.verScrollBar);
    add("HorScrollBar", horizontalBar());
    initInputActionMap();
    setMinimumSize(new Dimension(0, 0));
    initDefaultEditors();
  }

  protected JComponent horizontalBar()
  {
    return this.horScrollBar;
  }

  protected void initDefaultEditors()
  {
  }

  public abstract TemplateWorkBook getTemplate();

  public abstract TemplateWorkBook getBackUpTempalte();

  public abstract void setBackUpTemplate(TemplateWorkBook paramTemplateWorkBook);

  public TemplateReport getEditingReport()
  {
    return this._curReport;
  }

  public void setEditingReport(TemplateReport paramTemplateReport)
  {
    TemplateReport localTemplateReport = this._curReport;
    this._curReport = paramTemplateReport;
    if (this.grid != null)
      this.grid.removeAll();
    getGrid().setDrawingFloatElement(null);
    GridUtils.doSelectCell(this, 0, 0);
    firePropertyChange("report", localTemplateReport, this._curReport);
    validate();
    requestFocus();
  }

  public Grid getGrid()
  {
    return this.grid;
  }

  public GridColumn getGridColumn()
  {
    return this.gridColumn;
  }

  public GridRow getGridRow()
  {
    return this.gridRow;
  }

  public GridCorner getGridCorner()
  {
    return this.gridCorner;
  }

  public JScrollBar getVerticalScrollBar()
  {
    return this.verScrollBar;
  }

  public void setVerticalScrollBar(JScrollBar paramJScrollBar)
  {
    this.verScrollBar = paramJScrollBar;
  }

  public JScrollBar getHorizontalScrollBar()
  {
    return this.horScrollBar;
  }

  public void setHorizontalScrollBar(JScrollBar paramJScrollBar)
  {
    this.horScrollBar = paramJScrollBar;
  }

  public GridSelection getGridSelection()
  {
    return this.gridSelelction;
  }

  public void setGridSelection(GridSelection paramGridSelection)
  {
    if (paramGridSelection == null)
      return;
    if (!(ComparatorUtils.equals(this.gridSelelction, paramGridSelection)))
    {
      GridSelection localGridSelection = this.gridSelelction;
      this.gridSelelction = paramGridSelection;
    }
    this.gridSelelction = paramGridSelection;
  }

  public int getUndoLimit()
  {
    return this.undoLimit;
  }

  public void setUndoLimit(int paramInt)
  {
    this.undoLimit = paramInt;
  }

  public boolean isSupportUndo()
  {
    return this.supportUndo;
  }

  public void setSupportUndo(boolean paramBoolean)
  {
    this.supportUndo = paramBoolean;
  }

  public boolean isSupportDefaultParentCalculate()
  {
    return this.supportDefaultParentCalculate;
  }

  public void setSupportDefaultParentCalculate(boolean paramBoolean)
  {
    this.supportDefaultParentCalculate = paramBoolean;
  }

  public boolean isUndoCacheable()
  {
    return this.undoCacheable;
  }

  public void setUndoCacheable(boolean paramBoolean)
  {
    this.undoCacheable = paramBoolean;
  }

  public boolean cut()
  {
    copy();
    return innerClear(0);
  }

  public void copy()
  {
    GridSelection localGridSelection = getGridSelection();
    if ((localGridSelection.getType() == 0) && (localGridSelection.getCellRectangleCount() > 1))
    {
      JOptionPane.showMessageDialog(this, Inter.getLocText(""));
      return;
    }
    ElementsTransferable localElementsTransferable = GridUtils.caculateElementsTransferable(this);
    Object localObject1 = localElementsTransferable.getFirstObject();
    if ((localObject1 != null) && (localObject1 instanceof CellElementsClip))
    {
      localObject2 = (CellElementsClip)localObject1;
      ((CellElementsClip)localObject2).sortElementList();
      StringBuffer localStringBuffer = new StringBuffer();
      int i = -1;
      int j = ((CellElementsClip)localObject2).getCellElementCount();
      for (int k = 0; k < j; ++k)
      {
        CellElement localCellElement = ((CellElementsClip)localObject2).getCellElement(k);
        if (i == -1)
          i = localCellElement.getRow();
        if (i < localCellElement.getRow())
        {
          for (int l = i; l < localCellElement.getRow(); ++l)
            localStringBuffer.append('\n');
          i = localCellElement.getRow();
        }
        if ((localStringBuffer.length() > 0) && (localStringBuffer.charAt(localStringBuffer.length() - 1) != '\n'))
          localStringBuffer.append('\t');
        localStringBuffer.append(localCellElement.getValue());
      }
      localElementsTransferable.addObject(localStringBuffer.toString());
    }
    Object localObject2 = FRCoreContext.getClipboard(getGrid());
    ((Clipboard)localObject2).setContents(localElementsTransferable, localElementsTransferable);
  }

  public void formatBrush()
  {
    copy();
  }

  public boolean paste()
  {
    if (!(isEditable()))
      return false;
    TemplateReport localTemplateReport = getEditingReport();
    Clipboard localClipboard = FRCoreContext.getClipboard(getGrid());
    Transferable localTransferable = localClipboard.getContents(this);
    if (localTransferable == null)
      return false;
    GridSelection localGridSelection = getGridSelection();
    try
    {
      Object localObject1;
      Object localObject2;
      Object localObject3;
      try
      {
        localObject1 = ElementsTransferable.getElementNotStringTransderData(localTransferable);
      }
      catch (Exception localException2)
      {
        localObject1 = localTransferable.getTransferData(DataFlavor.stringFlavor);
      }
      if ((localObject1 instanceof FloatElementsClip) && (localGridSelection.getType() == 0))
      {
        localObject2 = (FloatElementsClip)((FloatElementsClip)localObject1).clone();
        localObject3 = localGridSelection.getEditRectangle();
        for (int i = 0; i < ((FloatElementsClip)localObject2).getFloatElementCount(); ++i)
        {
          FloatElement localFloatElement = ((FloatElementsClip)localObject2).getFloatElement(i);
          if (localObject3 != null)
          {
            localFloatElement.setColumn(((Rectangle)localObject3).x + localFloatElement.getColumn());
            localFloatElement.setRow(((Rectangle)localObject3).y + localFloatElement.getRow());
          }
          while (isContainSameBoundFloatElement(getEditingReport(), localFloatElement))
          {
            localFloatElement.setTopDistance(localFloatElement.getTopDistance() + 5);
            localFloatElement.setLeftDistance(localFloatElement.getLeftDistance() + 5);
          }
          localGridSelection.addFloatName(localFloatElement.getName());
          localTemplateReport.addFloatElement(localFloatElement);
        }
        label899: localGridSelection.setType(1);
      }
      else
      {
        Rectangle localRectangle1;
        int i1;
        int i2;
        int i3;
        int i4;
        Object localObject5;
        localObject2 = localGridSelection.getEditRectangle();
        localObject3 = new ArrayList();
        if ((localObject1 instanceof CellElementsClip) && (localGridSelection.getType() == 0))
        {
          CellElementsClip localCellElementsClip = (CellElementsClip)localObject1;
          k = localGridSelection.getCellRectangleCount();
          int l = 0;
          while (true)
          {
            if (l >= k)
              break label899;
            Rectangle localRectangle2 = localGridSelection.getCellRectangle(l);
            i2 = localRectangle2.x;
            i3 = localRectangle2.y;
            i4 = localCellElementsClip.getColumnSpan();
            int i5 = localCellElementsClip.getRowSpan();
            Iterator localIterator = localTemplateReport.intersect(i2, i3, i4, i5);
            while (localIterator.hasNext())
            {
              CellElement localCellElement2 = (CellElement)localIterator.next();
              localTemplateReport.removeCellElement(localCellElement2);
            }
            int i7 = localCellElementsClip.getCellElementCount();
            for (int i8 = 0; i8 < i7; ++i8)
            {
              localObject5 = (CellElement)localCellElementsClip.getCellElement(i8).clone();
              localTemplateReport.addCellElement(((CellElement)localObject5).deriveCellElement(i2 + ((CellElement)localObject5).getColumn(), i3 + ((CellElement)localObject5).getRow()), false);
            }
            Rectangle localRectangle5 = new Rectangle(i2, i3, i4, i5);
            ((List)localObject3).add(localRectangle5);
            ++l;
          }
        }
        if (localObject1 instanceof String)
        {
          j = localGridSelection.getCellRectangleCount();
          k = 0;
          while (true)
          {
            if (k >= j)
              break label899;
            localRectangle1 = localGridSelection.getCellRectangle(k);
            i1 = localRectangle1.x;
            i2 = localRectangle1.y;
            i3 = -2147483648;
            i4 = 0;
            String[] arrayOfString1 = Utils.splitString((String)localObject1, '\n');
            for (int i6 = 0; i6 < arrayOfString1.length; ++i6)
            {
              String[] arrayOfString2 = Utils.splitString(arrayOfString1[i6], '\t');
              for (int i9 = 0; i9 < arrayOfString2.length; ++i9)
              {
                localObject5 = arrayOfString2[i9];
                if (((String)localObject5).startsWith("="))
                {
                  localTemplateReport.setCellValue(i1 + i9, i2 + i6, new Formula((String)localObject5));
                }
                else
                {
                  Number localNumber = Utils.string2Number(arrayOfString2[i9]);
                  if (localNumber != null)
                  {
                    localTemplateReport.setCellValue(i1 + i9, i2 + i6, localNumber);
                  }
                  else
                  {
                    String str = Utils.replaceAllString(arrayOfString2[i9], ",", "");
                    localNumber = Utils.string2Number(str);
                    if (localNumber != null)
                      localTemplateReport.setCellValue(i1 + i9, i2 + i6, Utils.string2Number(str));
                    else
                      localTemplateReport.setCellValue(i1 + i9, i2 + i6, arrayOfString2[i9]);
                  }
                }
              }
            }
            Rectangle localRectangle4 = new Rectangle(i1, i2, i3, i4);
            ((List)localObject3).add(localRectangle4);
            ++k;
          }
        }
        int j = localGridSelection.getCellRectangleCount();
        for (int k = 0; k < j; ++k)
        {
          localRectangle1 = localGridSelection.getCellRectangle(k);
          i1 = localRectangle1.x;
          i2 = localRectangle1.y;
          Object localObject4 = localTemplateReport.getCellElement(i1, i2);
          if (localObject4 == null)
          {
            localObject4 = new DefaultCellElement(i1, i2, localObject1);
            localTemplateReport.addCellElement((CellElement)localObject4, false);
          }
          else
          {
            ((CellElement)localObject4).setValue(localObject1);
          }
          Rectangle localRectangle3 = new Rectangle(i1, i2, 1, 1);
          localGridSelection.addCellRectangle(localRectangle3);
        }
        localGridSelection.clearCellRectangles();
        if (((List)localObject3).size() > 0)
          localGridSelection.clearAllCellRectangles();
        for (j = 0; j < ((List)localObject3).size(); ++j)
          localGridSelection.addCellRectangle((Rectangle)((List)localObject3).get(j));
        CellElement localCellElement1 = localTemplateReport.getCellElement(((Rectangle)localObject2).x, ((Rectangle)localObject2).y);
        if (localCellElement1 != null)
          localGridSelection.setEditBounds(localCellElement1.getColumn(), localCellElement1.getRow(), localCellElement1.getColumnSpan(), localCellElement1.getRowSpan());
        else
          localGridSelection.setEditBounds(((Rectangle)localObject2).x, ((Rectangle)localObject2).y, 1, 1);
      }
    }
    catch (Exception localException1)
    {
      FRContext.getLogger().log(Level.WARNING, localException1.getMessage(), localException1);
      return false;
    }
    return true;
  }

  public boolean brushFormat()
  {
    if (!(isEditable()))
      return false;
    TemplateReport localTemplateReport = getEditingReport();
    Clipboard localClipboard = FRCoreContext.getClipboard(getGrid());
    Transferable localTransferable = localClipboard.getContents(this);
    if (localTransferable == null)
      return false;
    GridSelection localGridSelection = getGridSelection();
    try
    {
      Object localObject1;
      try
      {
        localObject1 = ElementsTransferable.getElementNotStringTransderData(localTransferable);
      }
      catch (Exception localException2)
      {
        localObject1 = localTransferable.getTransferData(DataFlavor.stringFlavor);
      }
      if ((localObject1 instanceof FloatElementsClip) && (localGridSelection.getType() == 0))
        break label1729:
      Rectangle localRectangle1 = localGridSelection.getEditRectangle();
      ArrayList localArrayList = new ArrayList();
      if ((localObject1 instanceof CellElementsClip) && (localGridSelection.getType() == 0))
      {
        localObject2 = (CellElementsClip)localObject1;
        int i = 0;
        while (true)
        {
          if (i >= localGridSelection.getCellRectangleCount())
            break label1653;
          Rectangle localRectangle2 = localGridSelection.getCellRectangle(i);
          int j = localRectangle2.x;
          int k = localRectangle2.y;
          int l = 0;
          int i1 = 0;
          if (((int)localRectangle2.getWidth() == 1) && ((int)localRectangle2.getHeight() == 1))
          {
            getGridSelection().clearAllCellRectangles();
            getGridSelection().addCellRectangle(new Rectangle(j, k, ((CellElementsClip)localObject2).getColumnSpan(), ((CellElementsClip)localObject2).getRowSpan()));
            unMergeCell();
            for (i2 = 0; i2 < ((CellElementsClip)localObject2).getColumnSpan(); ++i2)
              for (i3 = 0; i3 < ((CellElementsClip)localObject2).getRowSpan(); ++i3)
              {
                if (localTemplateReport.getCellElement(j + i2, k + i3) == null)
                  localTemplateReport.addCellElement(new DefaultCellElement(j + i2, k + i3), false);
                localTemplateReport.getCellElement(j + i2, k + i3).setStyle(Style.DEFAULT_STYLE);
              }
            i2 = 0;
            while (true)
            {
              if (i2 >= ((CellElementsClip)localObject2).getCellElementCount())
                break label1639;
              l = j + ((CellElementsClip)localObject2).getCellElement(i2).getColumn();
              i1 = k + ((CellElementsClip)localObject2).getCellElement(i2).getRow();
              localTemplateReport.getCellElement(l, i1).setStyle(((CellElementsClip)localObject2).getCellElement(i2).getStyle());
              if ((((CellElementsClip)localObject2).getCellElement(i2).getColumnSpan() > 1) || (((CellElementsClip)localObject2).getCellElement(i2).getRowSpan() > 1))
                localTemplateReport.merge(i1, i1 + ((CellElementsClip)localObject2).getCellElement(i2).getRowSpan() - 1, l, l + ((CellElementsClip)localObject2).getCellElement(i2).getColumnSpan() - 1);
              ++i2;
            }
          }
          unMergeCell();
          for (int i2 = 0; i2 < (int)localRectangle2.getWidth(); ++i2)
            for (i3 = 0; i3 < (int)localRectangle2.getHeight(); ++i3)
            {
              if (localTemplateReport.getCellElement(j + i2, k + i3) == null)
                localTemplateReport.setCellValue(j + i2, k + i3, "");
              localTemplateReport.getCellElement(j + i2, k + i3).setStyle(Style.DEFAULT_STYLE);
            }
          i2 = 0;
          int i3 = 0;
          for (i2 = 0; (i2 + 1) * ((CellElementsClip)localObject2).getColumnSpan() <= (int)localRectangle2.getWidth(); ++i2)
          {
            for (i3 = 0; (i3 + 1) * ((CellElementsClip)localObject2).getRowSpan() <= (int)localRectangle2.getHeight(); ++i3)
              for (i4 = 0; i4 < ((CellElementsClip)localObject2).getCellElementCount(); ++i4)
              {
                l = j + i2 * ((CellElementsClip)localObject2).getColumnSpan() + ((CellElementsClip)localObject2).getCellElement(i4).getColumn();
                i1 = k + i3 * ((CellElementsClip)localObject2).getRowSpan() + ((CellElementsClip)localObject2).getCellElement(i4).getRow();
                localTemplateReport.getCellElement(l, i1).setStyle(((CellElementsClip)localObject2).getCellElement(i4).getStyle());
                if ((((CellElementsClip)localObject2).getCellElement(i4).getColumnSpan() > 1) || (((CellElementsClip)localObject2).getCellElement(i4).getRowSpan() > 1))
                  localTemplateReport.merge(i1, i1 + ((CellElementsClip)localObject2).getCellElement(i4).getRowSpan() - 1, l, l + ((CellElementsClip)localObject2).getCellElement(i4).getColumnSpan() - 1);
              }
            for (i4 = 0; i4 < ((CellElementsClip)localObject2).getCellElementCount(); ++i4)
            {
              l = j + i2 * ((CellElementsClip)localObject2).getColumnSpan() + ((CellElementsClip)localObject2).getCellElement(i4).getColumn();
              i1 = k + i3 * ((CellElementsClip)localObject2).getRowSpan() + ((CellElementsClip)localObject2).getCellElement(i4).getRow();
              if ((l < j + (int)localRectangle2.getWidth()) && (i1 < k + (int)localRectangle2.getHeight()))
              {
                localTemplateReport.getCellElement(l, i1).setStyle(((CellElementsClip)localObject2).getCellElement(i4).getStyle());
                if ((Math.min(((CellElementsClip)localObject2).getCellElement(i4).getColumnSpan(), j + (int)localRectangle2.getWidth() - l) > 1) || (Math.min(((CellElementsClip)localObject2).getCellElement(i4).getRowSpan(), k + (int)localRectangle2.getHeight() - i1) > 1))
                  localTemplateReport.merge(i1, i1 + Math.min(((CellElementsClip)localObject2).getCellElement(i4).getRowSpan(), k + (int)localRectangle2.getHeight() - i1) - 1, l, l + Math.min(((CellElementsClip)localObject2).getCellElement(i4).getColumnSpan(), j + (int)localRectangle2.getWidth() - l) - 1);
              }
            }
          }
          for (i3 = 0; (i3 + 1) * ((CellElementsClip)localObject2).getRowSpan() <= (int)localRectangle2.getHeight(); ++i3)
            for (i4 = 0; i4 < ((CellElementsClip)localObject2).getCellElementCount(); ++i4)
            {
              l = j + i2 * ((CellElementsClip)localObject2).getColumnSpan() + ((CellElementsClip)localObject2).getCellElement(i4).getColumn();
              i1 = k + i3 * ((CellElementsClip)localObject2).getRowSpan() + ((CellElementsClip)localObject2).getCellElement(i4).getRow();
              if ((l < j + (int)localRectangle2.getWidth()) && (i1 < k + (int)localRectangle2.getHeight()))
              {
                localTemplateReport.getCellElement(l, i1).setStyle(((CellElementsClip)localObject2).getCellElement(i4).getStyle());
                if ((Math.min(((CellElementsClip)localObject2).getCellElement(i4).getColumnSpan(), j + (int)localRectangle2.getWidth() - l) > 1) || (Math.min(((CellElementsClip)localObject2).getCellElement(i4).getRowSpan(), k + (int)localRectangle2.getHeight() - i1) > 1))
                  localTemplateReport.merge(i1, i1 + Math.min(((CellElementsClip)localObject2).getCellElement(i4).getRowSpan(), k + (int)localRectangle2.getHeight() - i1) - 1, l, l + Math.min(((CellElementsClip)localObject2).getCellElement(i4).getColumnSpan(), j + (int)localRectangle2.getWidth() - l) - 1);
              }
            }
          for (int i4 = 0; i4 < ((CellElementsClip)localObject2).getCellElementCount(); ++i4)
          {
            l = j + i2 * ((CellElementsClip)localObject2).getColumnSpan() + ((CellElementsClip)localObject2).getCellElement(i4).getColumn();
            i1 = k + i3 * ((CellElementsClip)localObject2).getRowSpan() + ((CellElementsClip)localObject2).getCellElement(i4).getRow();
            if ((l < j + (int)localRectangle2.getWidth()) && (i1 < k + (int)localRectangle2.getHeight()))
            {
              localTemplateReport.getCellElement(l, i1).setStyle(((CellElementsClip)localObject2).getCellElement(i4).getStyle());
              if ((Math.min(((CellElementsClip)localObject2).getCellElement(i4).getColumnSpan(), j + (int)localRectangle2.getWidth() - l) > 1) || (Math.min(((CellElementsClip)localObject2).getCellElement(i4).getRowSpan(), k + (int)localRectangle2.getHeight() - i1) > 1))
                localTemplateReport.merge(i1, i1 + Math.min(((CellElementsClip)localObject2).getCellElement(i4).getRowSpan(), k + (int)localRectangle2.getHeight() - i1) - 1, l, l + Math.min(((CellElementsClip)localObject2).getCellElement(i4).getColumnSpan(), j + (int)localRectangle2.getWidth() - l) - 1);
            }
          }
          label1639: ++i;
        }
      }
      if (localObject1 instanceof String);
      label1653: Object localObject2 = localTemplateReport.getCellElement(localRectangle1.x, localRectangle1.y);
      label1729: if (localObject2 != null)
        localGridSelection.setEditBounds(((CellElement)localObject2).getColumn(), ((CellElement)localObject2).getRow(), ((CellElement)localObject2).getColumnSpan(), ((CellElement)localObject2).getRowSpan());
      else
        localGridSelection.setEditBounds(localRectangle1.x, localRectangle1.y, 1, 1);
    }
    catch (Exception localException1)
    {
      FRContext.getLogger().log(Level.WARNING, localException1.getMessage(), localException1);
      return false;
    }
    if (isFormatBrush())
      setFormatBrush(false);
    getGrid().setCursor(GUIConstants.CellDefaultCursor);
    repaint();
    return true;
  }

  public void ensureColumnRowVisible(int paramInt1, int paramInt2)
  {
    int k;
    Grid localGrid = getGrid();
    int i = localGrid.getVerticalValue() + localGrid.getVerticalExtent() + 1;
    int j = localGrid.getHorizontalValue() + localGrid.getHorizontalExtent() + 1;
    if (!(isRowEndless()))
    {
      k = getEditingReport().getRowCount();
      i = Math.min(i, k);
    }
    if (!(isColumnEndless()))
    {
      k = getEditingReport().getColumnCount();
      j = Math.min(j, k);
    }
    if (localGrid.getHorizontalValue() > paramInt1)
      getHorizontalScrollBar().setValue(paramInt1);
    else if (j <= paramInt1 + 1)
      getHorizontalScrollBar().setValue(paramInt1 - localGrid.getHorizontalExtent() + 1);
    if (localGrid.getVerticalValue() > paramInt2)
      getVerticalScrollBar().setValue(paramInt2);
    else if (i <= paramInt2 + 1)
      getVerticalScrollBar().setValue(paramInt2 - localGrid.getVerticalExtent() + 1);
  }

  private boolean isContainSameBoundFloatElement(Report paramReport, FloatElement paramFloatElement)
  {
    FloatElement localFloatElement;
    if (paramFloatElement == null)
      return false;
    Iterator localIterator = paramReport.floatIterator();
    do
    {
      if (!(localIterator.hasNext()))
        break label98;
      localFloatElement = (FloatElement)localIterator.next();
    }
    while ((localFloatElement.getColumn() != paramFloatElement.getColumn()) || (localFloatElement.getRow() != paramFloatElement.getRow()) || (localFloatElement.getTopDistance() != paramFloatElement.getTopDistance()) || (localFloatElement.getLeftDistance() != paramFloatElement.getLeftDistance()) || (!(ComparatorUtils.equals(localFloatElement.getSize(), paramFloatElement.getSize()))));
    return true;
    label98: return false;
  }

  public boolean clearAll()
  {
    return innerClear(0);
  }

  public boolean clearFormats()
  {
    return innerClear(1);
  }

  public boolean clearContents()
  {
    return innerClear(2);
  }

  public boolean canMergeCell()
  {
    GridSelection localGridSelection = getGridSelection();
    int i = localGridSelection.getType();
    if (i == 1)
      return false;
    Rectangle localRectangle = this.gridSelelction.getFirstCellRectangle();
    return ((localRectangle.width > 1) || (localRectangle.height > 1));
  }

  public boolean mergeCell()
  {
    if (!(canMergeCell()))
      return false;
    GridSelection localGridSelection = getGridSelection();
    int i = localGridSelection.getType();
    if (i == 1)
      return false;
    Rectangle localRectangle1 = localGridSelection.getEditRectangle();
    int j = localGridSelection.getCellRectangleCount();
    for (int k = 0; k < j; ++k)
    {
      Rectangle localRectangle2 = localGridSelection.getCellRectangle(k);
      if ((localRectangle2.width == 1) && (localRectangle2.height == 1))
        return false;
      TemplateReport localTemplateReport = getEditingReport();
      Iterator localIterator = localTemplateReport.intersect(localRectangle2.x, localRectangle2.y, localRectangle2.width, localRectangle2.height);
      if ((localIterator.hasNext()) && (localIterator.hasNext()))
      {
        int l = JOptionPane.showConfirmDialog(SwingUtilities.getWindowAncestor(this), Inter.getLocText("Des-Merger_Cell"), Inter.getLocText("Utils-Merge_Cell"), 2);
        if (l != 0)
          return false;
      }
      localTemplateReport.merge(localRectangle2.y, localRectangle2.y + localRectangle2.height - 1, localRectangle2.x, localRectangle2.x + localRectangle2.width - 1);
      if (localRectangle2.contains(localRectangle1))
        localRectangle1.setBounds(localRectangle2);
    }
    return true;
  }

  protected void mergeCellElementList(Report paramReport, List paramList)
  {
    CellElement localCellElement;
    if (paramList.size() <= 0)
      return;
    int i = paramList.size();
    int j = 0;
    int k = 0;
    Object localObject = (CellElement)paramList.get(0);
    for (int l = 0; l < i; ++l)
    {
      localCellElement = (CellElement)paramList.get(l);
      if (localCellElement.getRow() + localCellElement.getRowSpan() > k)
        k = localCellElement.getRow() + localCellElement.getRowSpan();
      if (localCellElement.getColumn() + localCellElement.getColumnSpan() > j)
        j = localCellElement.getColumn() + localCellElement.getColumnSpan();
      if (((localCellElement.getRow() < ((CellElement)localObject).getRow()) && (localCellElement.getColumn() < ((CellElement)localObject).getColumn())) || ((localCellElement.getRow() == ((CellElement)localObject).getRow()) && (localCellElement.getColumn() < ((CellElement)localObject).getColumn())) || ((localCellElement.getRow() < ((CellElement)localObject).getRow()) && (localCellElement.getColumn() == ((CellElement)localObject).getColumn())))
        localObject = localCellElement;
    }
    for (l = 0; l < i; ++l)
    {
      localCellElement = (CellElement)paramList.get(l);
      paramReport.removeCellElement(localCellElement);
    }
    paramReport.addCellElement(((CellElement)localObject).deriveCellElement(((CellElement)localObject).getColumn(), ((CellElement)localObject).getRow(), j - ((CellElement)localObject).getColumn(), k - ((CellElement)localObject).getRow()));
  }

  public boolean canUnMergeCell()
  {
    GridSelection localGridSelection = getGridSelection();
    if (localGridSelection.getType() == 1)
      return false;
    TemplateReport localTemplateReport = getEditingReport();
    for (int i = 0; i < localGridSelection.getCellRectangleCount(); ++i)
    {
      CellElement localCellElement;
      Rectangle localRectangle = localGridSelection.getCellRectangle(i);
      Iterator localIterator = localTemplateReport.intersect(localRectangle.x, localRectangle.y, localRectangle.width, localRectangle.height);
      do
      {
        if (!(localIterator.hasNext()))
          break label111;
        localCellElement = (CellElement)localIterator.next();
      }
      while ((localCellElement.getColumnSpan() <= 1) && (localCellElement.getRowSpan() <= 1));
      return true;
    }
    label111: return false;
  }

  public boolean unMergeCell()
  {
    if (!(canUnMergeCell()))
      return false;
    TemplateReport localTemplateReport = getEditingReport();
    GridSelection localGridSelection = getGridSelection();
    for (int i = 0; i < localGridSelection.getCellRectangleCount(); ++i)
    {
      Rectangle localRectangle2 = localGridSelection.getCellRectangle(i);
      Iterator localIterator = localTemplateReport.intersect(localRectangle2.x, localRectangle2.y, localRectangle2.width, localRectangle2.height);
      if (localIterator.hasNext())
      {
        CellElement localCellElement = (CellElement)localIterator.next();
        int j = localCellElement.getColumnSpan();
        int k = localCellElement.getRowSpan();
        getEditingReport().removeCellElement(localCellElement);
        getEditingReport().addCellElement(localCellElement.deriveCellElement(localCellElement.getColumn(), localCellElement.getRow(), 1, 1));
        int l = localCellElement.getColumn();
        while (true)
        {
          if (l >= localCellElement.getColumn() + j);
          for (int i1 = localCellElement.getRow(); i1 < localCellElement.getRow() + k; ++i1)
          {
            if ((l == localCellElement.getColumn()) && (i1 == localCellElement.getRow()))
              break label244:
            getEditingReport().addCellElement(new DefaultCellElement(l, i1), false);
          }
          ++l;
        }
      }
    }
    label244: Rectangle localRectangle1 = localGridSelection.getEditRectangle();
    localRectangle1.setBounds(localRectangle1.x, localRectangle1.y, 1, 1);
    return true;
  }

  public void fireGridSelectionChanged()
  {
    fireGridSelectionChangeListener();
    repaint(15L);
  }

  public void addGridSelectionChangeListener(GridSelectionChangeListener paramGridSelectionChangeListener)
  {
    this.gridSelectionChangeListenerList.add(GridSelectionChangeListener.class, paramGridSelectionChangeListener);
  }

  public void removeGridSelectionChangeListener(GridSelectionChangeListener paramGridSelectionChangeListener)
  {
    this.gridSelectionChangeListenerList.remove(GridSelectionChangeListener.class, paramGridSelectionChangeListener);
  }

  public void fireGridSelectionChangeListener()
  {
    Object[] arrayOfObject = this.gridSelectionChangeListenerList.getListenerList();
    for (int i = arrayOfObject.length - 2; i >= 0; i -= 2)
      if (arrayOfObject[i] == GridSelectionChangeListener.class)
      {
        if (this.gridSelectionChangeEvent == null)
          this.gridSelectionChangeEvent = new GridSelectionChangeEvent(this);
        ((GridSelectionChangeListener)arrayOfObject[(i + 1)]).gridSelectionChanged(this.gridSelectionChangeEvent);
      }
  }

  public void fireReportDataChanged()
  {
    TemplateReport localTemplateReport = getEditingReport();
    if (isSupportDefaultParentCalculate())
      SheetUtils.calculateDefaultParent(localTemplateReport);
    fireReportDataChangeListener();
    repaint(10L);
  }

  public void addReportDataChangeListener(ReportDataChangeListener paramReportDataChangeListener)
  {
    this.reportDataChangeListenerList.add(ReportDataChangeListener.class, paramReportDataChangeListener);
  }

  public void removeReportDataChangeListener(ReportDataChangeListener paramReportDataChangeListener)
  {
    this.reportDataChangeListenerList.remove(ReportDataChangeListener.class, paramReportDataChangeListener);
  }

  public void fireReportDataChangeListener()
  {
    Object[] arrayOfObject = this.reportDataChangeListenerList.getListenerList();
    for (int i = arrayOfObject.length - 2; i >= 0; i -= 2)
      if (arrayOfObject[i] == ReportDataChangeListener.class)
      {
        if (this.reportDataChangeEvent == null)
          this.reportDataChangeEvent = new ReportDataChangeEvent(this);
        ((ReportDataChangeListener)arrayOfObject[(i + 1)]).reportDataChanged(this.reportDataChangeEvent);
      }
  }

  protected void initInputActionMap()
  {
    InputMap localInputMap = getInputMap(1);
    ActionMap localActionMap = getActionMap();
    localInputMap.clear();
    localActionMap.clear();
    localInputMap.put(KeyStroke.getKeyStroke(88, 2), "cut");
    localActionMap.put("cut", new AbstractAction(this)
    {
      private final ReportPane this$0;

      public void actionPerformed()
      {
        if (this.this$0.cut())
        {
          this.this$0.fireReportDataChanged();
          this.this$0.undoRecord();
        }
      }
    });
    localInputMap.put(KeyStroke.getKeyStroke(67, 2), "copy");
    localActionMap.put("copy", new AbstractAction(this)
    {
      private final ReportPane this$0;

      public void actionPerformed()
      {
        this.this$0.copy();
      }
    });
    localInputMap.put(KeyStroke.getKeyStroke(86, 2), "paste");
    localActionMap.put("paste", new AbstractAction(this)
    {
      private final ReportPane this$0;

      public void actionPerformed()
      {
        if (this.this$0.paste())
        {
          this.this$0.fireReportDataChanged();
          this.this$0.undoRecord();
        }
      }
    });
    localInputMap.put(KeyStroke.getKeyStroke(127, 0), "delete_content");
    localActionMap.put("delete_content", new AbstractAction(this)
    {
      private final ReportPane this$0;

      public void actionPerformed()
      {
        if (this.this$0.clearContents())
        {
          this.this$0.fireReportDataChanged();
          this.this$0.undoRecord();
        }
      }
    });
    localInputMap.put(KeyStroke.getKeyStroke(127, 2), "delete_all");
    localActionMap.put("delete_all", new AbstractAction(this)
    {
      private final ReportPane this$0;

      public void actionPerformed()
      {
        if (this.this$0.clearAll())
        {
          this.this$0.fireReportDataChanged();
          this.this$0.undoRecord();
        }
      }
    });
  }

  public boolean isColumnHeaderVisible()
  {
    return this.columnHeaderVisible;
  }

  public void setColumnHeaderVisible(boolean paramBoolean)
  {
    boolean bool = this.columnHeaderVisible;
    this.columnHeaderVisible = paramBoolean;
    firePropertyChange("columnHeaderVisible", bool, this.columnHeaderVisible);
    resizeAndRepaint();
  }

  public boolean isRowHeaderVisible()
  {
    return this.rowHeaderVisible;
  }

  public void setRowHeaderVisible(boolean paramBoolean)
  {
    boolean bool = this.rowHeaderVisible;
    this.rowHeaderVisible = paramBoolean;
    firePropertyChange("rowHeaderVisible", bool, this.rowHeaderVisible);
    resizeAndRepaint();
  }

  public boolean isVerticalScrollBarVisible()
  {
    return this.verticalScrollBarVisible;
  }

  public void setVerticalScrollBarVisible(boolean paramBoolean)
  {
    this.verticalScrollBarVisible = paramBoolean;
  }

  public boolean isHorizontalScrollBarVisible()
  {
    return this.horizontalScrollBarVisible;
  }

  public void setHorizontalScrollBarVisible(boolean paramBoolean)
  {
    this.horizontalScrollBarVisible = paramBoolean;
  }

  public boolean isEditable()
  {
    return this.grid.isEditable();
  }

  public void setEditable(boolean paramBoolean)
  {
    this.grid.setEditable(paramBoolean);
  }

  public boolean isColumnEndless()
  {
    return this.columnEndless;
  }

  public void setColumnEndless(boolean paramBoolean)
  {
    boolean bool = this.columnEndless;
    this.columnEndless = paramBoolean;
    firePropertyChange("columnEndless", bool, this.columnEndless);
    resizeAndRepaint();
  }

  public boolean isRowEndless()
  {
    return this.rowEndless;
  }

  public void setRowEndless(boolean paramBoolean)
  {
    boolean bool = this.rowEndless;
    this.rowEndless = paramBoolean;
    firePropertyChange("rowEndless", bool, this.rowEndless);
    resizeAndRepaint();
  }

  public boolean isFormatBrush()
  {
    return this.isFormatBrush;
  }

  public void setFormatBrush(boolean paramBoolean)
  {
    this.isFormatBrush = paramBoolean;
  }

  public void showWidgetWindow()
  {
  }

  public JPopupMenu createPopupMenu(MouseEvent paramMouseEvent)
  {
    return null;
  }

  public JPopupMenu createRowPopupMenu(MouseEvent paramMouseEvent, int paramInt)
  {
    return null;
  }

  public JPopupMenu createColumnPopupMenu(MouseEvent paramMouseEvent, int paramInt)
  {
    return null;
  }

  protected boolean innerClear(int paramInt)
  {
    Object localObject1;
    int j;
    Object localObject2;
    GridSelection localGridSelection = getGridSelection();
    if (localGridSelection.getType() == 1)
    {
      getGrid().stopEditing();
      getEditingReport().removeFloatElement(localGridSelection.getLastFloatName());
      localGridSelection.removeFloatName(localGridSelection.getLastFloatName());
      localObject1 = getEditingReport().floatIterator();
      if (!(((Iterator)localObject1).hasNext()))
      {
        localGridSelection.setType(0);
        localGridSelection.setEditBounds(0, 0, 1, 1);
        localGridSelection.setOnlyCellBounds(0, 0, 1, 1);
      }
      else
      {
        localGridSelection.setType(1);
        if (localGridSelection.getFloatNameCount() == 0)
          localGridSelection.addFloatName(((FloatElement)((Iterator)localObject1).next()).getName());
      }
    }
    else
    {
      localObject1 = new ArrayList();
      for (int i = 0; i < localGridSelection.getCellRectangleCount(); ++i)
      {
        Rectangle localRectangle = localGridSelection.getCellRectangle(i);
        localObject2 = getEditingReport().intersect(localRectangle.x, localRectangle.y, localRectangle.width, localRectangle.height);
        while (((Iterator)localObject2).hasNext())
        {
          CellElement localCellElement = (CellElement)((Iterator)localObject2).next();
          CellGUIAttr localCellGUIAttr = localCellElement.getCellGUIAttr();
          if (localCellGUIAttr == null)
            localCellGUIAttr = CellGUIAttr.DEFAULT_CELLGUIATTR;
          ((List)localObject1).add(localCellElement);
        }
      }
      if (((List)localObject1).size() == 0)
        return false;
      switch (paramInt)
      {
      case 0:
        TemplateReport localTemplateReport = getEditingReport();
        j = 0;
        while (true)
        {
          if (j >= ((List)localObject1).size())
            break label427;
          localObject2 = ((List)localObject1).get(j);
          if (localObject2 instanceof CellElement)
            localTemplateReport.removeCellElement((CellElement)localObject2);
          ++j;
        }
      case 1:
        j = 0;
        while (true)
        {
          if (j >= ((List)localObject1).size())
            break label427;
          localObject2 = ((List)localObject1).get(j);
          if (localObject2 instanceof CellElement)
            ((CellElement)localObject2).setStyle(null);
          ++j;
        }
      case 2:
        for (j = 0; j < ((List)localObject1).size(); ++j)
        {
          localObject2 = ((List)localObject1).get(j);
          if (localObject2 instanceof CellElement)
            ((CellElement)localObject2).setValue(null);
        }
      }
    }
    label427: return true;
  }

  public void requestFocus()
  {
    getGrid().requestFocus();
  }

  protected void resizeAndRepaint()
  {
    revalidate();
    repaint();
  }

  protected void processMouseWheelEvent(MouseWheelEvent paramMouseWheelEvent)
  {
    int i = paramMouseWheelEvent.getID();
    switch (i)
    {
    case 507:
      int j = paramMouseWheelEvent.getWheelRotation();
      getVerticalScrollBar().setValue(getVerticalScrollBar().getValue() + j * 3);
    }
  }

  private UndoManager getUndoManager()
  {
    if (this.undoMananger == null)
    {
      this.undoMananger = new UndoManager();
      this.undoMananger.setLimit(getUndoLimit());
    }
    return this.undoMananger;
  }

  public boolean canUndo()
  {
    return getUndoManager().canUndo();
  }

  public boolean canRedo()
  {
    return getUndoManager().canRedo();
  }

  public void undo()
  {
    getUndoManager().undo();
  }

  public void redo()
  {
    getUndoManager().redo();
  }

  public void undoRecord()
  {
    if (this.supportUndo)
    {
      UndoState localUndoState = createUndoState();
      if (localUndoState != null)
      {
        getUndoManager().addEdit(new UndoStateEdit(this.currentUndoState, localUndoState));
        setUndoState(localUndoState);
      }
    }
  }

  public void setUndoState(UndoState paramUndoState)
  {
    this.currentUndoState = paramUndoState;
  }

  protected UndoState createUndoState()
  {
    return null;
  }

  protected abstract void changeBackUpTempalte(TemplateWorkBook paramTemplateWorkBook);
}